package com.itheima03.day16test;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 刘全
 * @date 2021/8/10
 */
public class ServerTest6 {
    public static void main(String[] args) throws IOException {
        /**
         * 6. 使用TCP完成文件上传。
         */
        ServerSocket ss = new ServerSocket(10086);

        Socket accept = ss.accept();
        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("马保国.gif"));

        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();

        bos.close();
        accept.close();
        ss.close();
    }
}
